package com.community.contents.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.community.common.core.utils.Result;
import com.community.contents.entity.SlideshowEntity;
import com.community.contents.service.SlideshowService;
import com.community.contents.vo.SlideshowVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @className: SlideshowController
 * @author: shuishui
 * @date: 2023/02/28 17:15
 */
@RestController
@RequestMapping("/slideshow")
@Api(tags="主页")
public class SlideshowController {
    @Autowired
    private SlideshowService slideshowService;

    @GetMapping("/getSlideshow")
    public Result getSlideshow(@RequestParam("type") Integer id){
//        LambdaQueryWrapper<SlideshowEntity> wrapper = new LambdaQueryWrapper<>();
//        wrapper.select(SlideshowEntity::getPicture);
        List<SlideshowEntity> list = slideshowService.list();
        List listpicture = new ArrayList();
        List listId = new ArrayList();
        Map map = new HashMap();
        for (SlideshowEntity i:
             list) {
            listpicture.add(i.getPicture());
            listId.add(i.getTopicId());
        }
        map.put("picture",listpicture);
        map.put("topicId",listId);
//        for (int i = 0; i < list.size(); i++) {
//            listpicture.add(list)
//        }
        return new Result().ViewOk(map);
    }
    @GetMapping("/selectAll")
    public List<SlideshowVO> selectAll(){
        List<SlideshowVO> slideshowVOS = slideshowService.SelectALL();
        return slideshowVOS;

    }
    @GetMapping("/removeById/{id}")
    public boolean removeById(@PathVariable Integer id){
        return slideshowService.removeById(id);
    }
    @PostMapping("/save")
    public boolean update(@RequestBody SlideshowEntity slideshowEntity){
        Date date = new Date();
//        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
        slideshowEntity.setCreatTime(date);

        return slideshowService.save(slideshowEntity);
    }
}
